/*
 * @Author: Kang
 * @Date: 2021-11-23 11:19:40
 * @Last Modified by: Kang
 * @LastEditTime: 2022-09-05 11:07:11
 */
/* eslint valid-jsdoc: 'off' */

'use strict';
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1637637570990_1815';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  /* 取消安全证书验证 */
  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList: ['*'], // 白名单
  };

  config.session = {
    key: 'EGG_SESS',
    maxAge: 5 * 1000 * 60, // 5 分钟
    httpOnly: true,
    encrypt: true,
  };

  config.email = {
    host: 'smtp.163.com', //邮件host
    name: '', // 邮件名
    password: '',  //   ,授权码登录
    to: '2374500210@qq.com' //发送给谁
  };

  config.sequelize = {
    dialect: 'mysql',
    host: '',
    port: 61572,
    username: 'root',
    password: '',
    database: '',
    define: {
      operatorsAliases: false,
      freezeTableName: true, // Model 对应的表名将与model名相同。
      timestamps: false, // 默认情况下，Sequelize会将createdAt和updatedAt的属性添加到模型中，以便您可以知道数据库条目何时进入数据库以及何时被更新（ 确实是太方便了，然而我们一般用不到 ....）。
    },
  };
  config.jwt = {
    secret: 'kang123', // 自定义加密字符串，secret 是在服务端的，不要泄露
    expiresIn: '1h'
  };
  config.multipart = {
    mode: 'stream',
    fileSize: '50mb',
    fileExtensions: ['.pdf', '.docx'], // 扩展几种上传的文件格式
  };
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH' // 表示允许的http请求方式
  };
  config.middleware = ["jwtValidate"];
  // egg-swagger-doc 配置信息。
  config.swaggerdoc = {
    dirScanner: './app/controller',
    basePath: '/',
    apiInfo: {
      title: 'ksl-swagger',
      description: 'swagger-ui for ksl js api',
      version: '1.0.0',
    },
    schemes: ['http', 'https'],
    consumes: ['application/json'],
    produces: ['application/json'],
    securityDefinitions: {
      // apikey: {
      //   type: 'apiKey',
      //   name: 'clientkey',
      //   in: 'header',
      // },
      // oauth2: {
      //   type: 'oauth2',
      //   tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
      //   flow: 'password',
      //   scopes: {
      //     'write:access_token': 'write access_token',
      //     'read:access_token': 'read access_token',
      //   },
      // },
    },
    enableSecurity: false,
    // enableValidate: true,
    routerMap: false,
    enable: true,
  };

  return {
    ...config,
    ...userConfig,
  };
};
